import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import compressPlugin from 'vite-plugin-compression'
import path from 'path'
// https://vite.dev/config/
export default defineConfig({
  plugins: [react(),
  compressPlugin({
    algorithm: 'gzip',
  }),
  {
    name: 'my-plugin',
    transform(code: any, id: any) {
      if (id.includes('node_modules')) return null;
      return code.replace(/console\.log/g, 'console.info')
    }
  }
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://172.27.2.110',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  },
  build: {
    rollupOptions: {
      output: {
        chunkFileNames: 'js/[name]-[hash].js',
        assetFileNames: '[ext]/[name]-[hash].[ext]',
      },
    },
  }
})
